package com.morninz.ninepinview;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.morninz.ninepinview.widget.NinePINView;
import com.morninz.ninepinview.widget.NinePINView.Mode;
import com.morninz.ninepinview.widget.NinePINView.OnDrawListener;
import com.morninz.ninepinview.widget.PasscodeView;

public class DemoActivity extends Activity {

	TextView mTextViewResult;
	// NinePINView mNinePINView;
	PasscodeView mPasscodeView;
	NinePINView mNinePINView;
	String mCorrectPin;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.demo_activity);
		mTextViewResult = (TextView) findViewById(R.id.result);
		// mPasscodeView = (PasscodeView) findViewById(R.id.nine_pin_view);
		// mPasscodeView.setMode(Mode.MODE_STUDY);
		// mPasscodeView.setType(PasscodeView.TYPE_1);
		// mTextViewResult.setText("");
		// mPasscodeView.setOnDrawListener(new OnDrawListener() {
		//
		// @Override
		// public void onDrawStart(PasscodeView ninePINView) {
		// mTextViewResult.setText("");
		// }
		//
		// @Override
		// public void onDrawComplete(PasscodeView ninePINView, boolean correct)
		// {
		// String drawnPIN = ninePINView.getDrawnPIN();
		// Mode mode = ninePINView.getMode();
		// if (mode == Mode.MODE_STUDY) {
		// mTextViewResult.setText("Study Completeï¼�" + drawnPIN);
		// mCorrectPin = drawnPIN;
		// ninePINView.setCorrectPIN(mCorrectPin);
		// ninePINView.setMode(Mode.MODE_WORK);
		// } else if (mode == Mode.MODE_WORK) {
		// if (correct) {
		// mTextViewResult.setText("Draw Correctï¼�" + drawnPIN);
		// } else {
		// mTextViewResult.setText("Draw Wrongï¼�" + drawnPIN);
		// }
		// }
		// }
		//
		// @Override
		// public void onValueSelected(PasscodeView passcodeView, int value) {
		// // TODO Auto-generated method stub
		// StringBuilder sb = new StringBuilder(mTextViewResult.getText());
		// sb.append(value);
		// mTextViewResult.setText(sb.toString());
		// }
		//
		// @Override
		// public void onBacked(PasscodeView passcodeView) {
		// // TODO Auto-generated method stub
		// Toast.makeText(getApplicationContext(), "Backed", 1000).show();
		// Log.d("Kai", "Backed");
		//
		// }
		//
		// @Override
		// public void onDelete(PasscodeView passcodeView) {
		// // TODO Auto-generated method stub
		// // Toast.makeText(getApplicationContext(), "Deleted", 1000).show();
		// StringBuilder sb = new StringBuilder(mTextViewResult.getText());
		// sb.deleteCharAt(sb.length()-1);
		// mTextViewResult.setText(sb.toString());
		// }
		// });

		mNinePINView = (NinePINView) findViewById(R.id.nine_pin_view);

		mNinePINView.setMode(Mode.MODE_STUDY);
		mNinePINView.setType(PasscodeView.TYPE_1);
		mNinePINView.setOnDrawListener(new OnDrawListener() {

			@Override
			public void onDrawStart(NinePINView ninePINView) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onDrawComplete(NinePINView ninePINView, boolean correct) {
				// TODO Auto-generated method stub
				mTextViewResult.setText(mNinePINView.getMode() + "");
			}

			@Override
			public void onBacked(NinePINView passcodeView) {
				// TODO Auto-generated method stub
//				finish();
				Log.d("Kai", "backed");
				finish();
			}
		});
	}
}
